package com.woniuxy.joylifecenter.service.impl;

import java.util.*;

import com.woniuxy.common.entity.CenterUser;
import com.woniuxy.common.entity.CenterUserExample;
import com.woniuxy.common.mapper.CenterUserMapper;
import com.woniuxy.joylifecenter.service.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserManageServiceImpl implements UserManageService {
    @Autowired
    CenterUserMapper centerUserMapper;

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Author ArmWatt
     * @Date 2020/5/13
     * @Param []
     * @Description 查询所有待审批的用户认证
     **/
    @Override
    public List<Map<String, Object>> queryAllUserApply() {
        return centerUserMapper.selectAllUserApply();
    }

    /**
     * @param id
     * @return int
     * @Author ArmWatt
     * @Date 2020/5/13
     * @Param [id]
     * @Description 通过用户认证
     */
    @Override
    public int passUserApply(String id) {
        return centerUserMapper.passUserApply(id);
    }

    /**
     * @param id
     * @return int
     * @Author ArmWatt
     * @Date 2020/5/13
     * @Param [id]
     * @Description 用户认证拒绝
     */
    @Override
    public int rejectUserApply(String id) {
        return centerUserMapper.rejectUserApply(id);
    }

    /**
     * @param centerUser
     * @return java.util.List<com.woniuxy.common.entity.CenterUser>
     * @Author ArmWatt
     * @Date 2020/5/16
     * @Param [centerUser]
     * @Description 多条件模糊查询用户
     */
    @Override
    public List<CenterUser> selectUserByCondition(CenterUser centerUser) {
        CenterUserExample example = new CenterUserExample();
        CenterUserExample.Criteria criteria = example.createCriteria();
        if (centerUser.getCenterCredentialcode() != null) {
            criteria.andCenterCredentialcodeLike("%" + centerUser.getCenterCredentialcode() + "%");
        }
        if (centerUser.getCenterAccountstatus() != null) {
            criteria.andCenterAccountstatusEqualTo(centerUser.getCenterAccountstatus());
        }
        if (centerUser.getCenterUsertype() != null) {
            criteria.andCenterUsertypeEqualTo(centerUser.getCenterUsertype());
        }
        if (centerUser.getCoin() != null) {
            criteria.andCoinGreaterThanOrEqualTo(centerUser.getCoin());
        }
        if (centerUser.getDate() != null) {
            criteria.andDateGreaterThan(centerUser.getDate());
        }
        if (centerUser.getEmail() != null) {
            criteria.andEmailLike("%" + centerUser.getEmail() + "%");
        }
        if (centerUser.getForumId() != null) {
            criteria.andForumIdLike("%" + centerUser.getForumId() + "%");
        }
        if (centerUser.getId() != null) {
            criteria.andIdLike("%" + centerUser.getId() + "%");
        }
        if (centerUser.getIntro() != null) {
            criteria.andIntroLike("%" + centerUser.getIntro() + "%");
        }
        if (centerUser.getName() != null) {
            criteria.andNameLike("%" + centerUser.getName() + "%");
        }
        if (centerUser.getNickname() != null) {
            criteria.andNicknameLike("%" + centerUser.getNickname() + "%");
        }
        if (centerUser.getPhone() != null) {
            criteria.andPhoneLike("%" + centerUser.getPhone() + "%");
        }

        example.setOrderByClause("'date' DESC");
        return centerUserMapper.selectByExample(example);

    }

    /**
     * @param id
     * @return int
     * @Author ArmWatt
     * @Date 2020/5/16
     * @Param [id]
     * @Description 封号
     */
    @Override
    public int suspendAccount(String id) {
        return centerUserMapper.suspendUser(id);

    }

    /**
     * @param id
     * @return int
     * @Author ArmWatt
     * @Date 2020/5/16
     * @Param [id]
     * @Description 账号解封
     */
    @Override
    public int unsuspendAccount(String id) {
        return centerUserMapper.unsuspendUser(id);
    }

    /**
     * @param id
     * @return int
     * @Author ArmWatt
     * @Date 2020/5/16
     * @Param [id]
     * @Description 重置密码
     */
    @Override
    public int resetPassWord(String id) {
        return centerUserMapper.resetPassWord(id);
    }
}
